package com.example.myvideo.View;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myvideo.R;
import com.example.myvideo.View.impl.AuthModelImpl;
import com.example.myvideo.View.impl.AuthPresenterImpl;
import com.example.myvideo.contract.AuthView;
import com.example.myvideo.database.DBHelper;
import com.example.myvideo.model.AuthModel;
import com.example.myvideo.presenter.AuthPresenter;

public class LoginActivity extends AppCompatActivity implements AuthView {
    private AuthPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        // 初始化Presenter
        DBHelper dbHelper = new DBHelper(this); // 创建 DBHelper 实例
        AuthModel model = new AuthModelImpl(this, dbHelper);
        presenter = new AuthPresenterImpl(this, model, dbHelper);
        // 设置按钮点击事件等
        Button registerButton = findViewById(R.id.btnregister);
        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void showLoading() {
        // 显示加载动画
    }

    @Override
    public void hideLoading() {
        // 隐藏加载动画
    }

    @Override
    public void showErrorMessage(String message) {
        // 显示错误消息
    }

    @Override
    public void navigateToHomeScreen() {
        // 跳转到主界面
    }

    @Override
    public void showUsernameError() {
        // 显示用户名错误
    }

    @Override
    public void showPasswordError() {
        // 显示密码错误
    }

    @Override
    public void showRegistrationSuccess() {

    }

    // 登录按钮点击事件
    public void onLoginClick(View view) {
        String username = ((EditText) findViewById(R.id.etUsername)).getText().toString();
        String password = ((EditText) findViewById(R.id.etPassword)).getText().toString();
        presenter.login(username, password);
    }
}